#define _CRT_SECURE_NO_WARNINGS 1

#include "SingleLinkedList1.h"

void TestPushFront();
void TestPushBack();
void TestInsertBefore();
void TestInsertAfter();

void TestClear();
void TestPopFront();
void TestPopBack();
void TestErase();
void TestEraseBefore();
void TestEraseAfter();
void TestRemove();


int main() {
	//TestPushFront();
	//TestPushBack();
	//TestInsertBefore();
	//TestInsertAfter();

	//TestClear();
	//TestPopFront();
	//TestPopBack();
	//TestErase();
	//TestRemove();
	//TestEraseBefore();
	TestEraseAfter();
	return 0;
}

void TestPushFront() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PrintList(&list);
}

void TestPushBack() {
	ListNode* list = NULL;
	PushBack(&list, 100);
	PushBack(&list, 200);
	PushBack(&list, 300);
	PushBack(&list, 400);
	PrintList(&list);
}

void TestInsertBefore() {
	ListNode* list = NULL;
	InsertBefore(&list, NULL, 500);
	InsertBefore(&list, Find(&list, 500), 400);
	InsertBefore(&list, Find(&list, 400), 300);
	InsertBefore(&list, NULL, 600);
	InsertBefore(&list, Find(&list, 400), 399);
	PrintList(&list);
}

void TestInsertAfter() {
	ListNode* list = NULL;
	PushBack(&list, 100);
	InsertAfter(&list, Find(&list, 100), 200);
	InsertAfter(&list, Find(&list, 200), 300);
	InsertAfter(&list, Find(&list, 300), 400);
	PrintList(&list);
}

void TestClear() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PrintList(&list);
	Clear(&list);
	PrintList(&list);
}

void TestPopFront() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PrintList(&list);
	PopFront(&list);
	PopFront(&list);
	PopFront(&list);
	PopFront(&list);
	PrintList(&list);
}

void TestPopBack() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PrintList(&list);
	PopBack(&list);
	PopBack(&list);
	PopBack(&list);
	PopBack(&list);
	PrintList(&list);
}

void TestErase() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PushFront(&list, 500);
	PrintList(&list);
	Erase(&list, Find(&list, 100));
	PrintList(&list);
	Erase(&list, Find(&list, 400));
	PrintList(&list);
	Erase(&list, Find(&list, 500));
	PrintList(&list);
	Erase(&list, Find(&list, 200));
	PrintList(&list);
	Erase(&list, Find(&list, 300));
	PrintList(&list);
	//Erase(&list, NULL);
	//PrintList(&list);
}

void TestEraseBefore() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PushFront(&list, 500);
	PrintList(&list);
	
	EraseBefore(&list, NULL); 
	PrintList(&list);
	EraseBefore(&list, Find(&list, 500)); 
	PrintList(&list);
	EraseBefore(&list, Find(&list, 400)); 
	PrintList(&list);
	EraseBefore(&list, Find(&list, 200));
	PrintList(&list);
}

void TestEraseAfter() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PrintList(&list);

	//EraseAfter(&list, NULL);
	EraseAfter(&list, Find(&list, 100));
	PrintList(&list);
	EraseAfter(&list, Find(&list, 400));
	PrintList(&list);
	EraseAfter(&list, Find(&list, 200));
	PrintList(&list);
}

void TestRemove() {
	ListNode* list = NULL;
	PushFront(&list, 100);
	PushFront(&list, 200);
	PushFront(&list, 300);
	PushFront(&list, 400);
	PushFront(&list, 500);
	PrintList(&list);
	Remove(&list, 1000);
	PrintList(&list);
	Remove(&list, 100);
	PrintList(&list);
	Remove(&list, 300);
	PrintList(&list);
	Remove(&list, 500);
	PrintList(&list);
}